package com.ruoyi.web.controller.resource;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.resource.domain.ResStation;
import com.ruoyi.resource.service.IResStationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小站Controller
 * 
 * @author ruoyi
 * @date 2022-01-16
 */
@RestController
@RequestMapping("/resource/station")
public class ResStationController extends BaseController
{
    @Autowired
    private IResStationService resStationService;

    /**
     * 查询小站列表
     */
    @PreAuthorize("@ss.hasPermi('resource:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResStation resStation)
    {
        startPage();
        List<ResStation> list = resStationService.selectResStationList(resStation);
        return getDataTable(list);
    }

    /**
     * 查询小站热门列表
     */
    @GetMapping("/hotList")
    public TableDataInfo hotList(ResStation resStation)
    {
        startPage();
        List<ResStation> list = resStationService.selectResStationHotList(resStation);
        return getDataTable(list);
    }

    /**
     * 导出小站列表
     */
    @PreAuthorize("@ss.hasPermi('resource:station:export')")
    @Log(title = "小站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResStation resStation)
    {
        List<ResStation> list = resStationService.selectResStationList(resStation);
        ExcelUtil<ResStation> util = new ExcelUtil<ResStation>(ResStation.class);
        util.exportExcel(response, list, "小站数据");
    }

    /**
     * 获取小站详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:station:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resStationService.selectResStationById(id));
    }

    /**
     * 新增小站
     */
    @PreAuthorize("@ss.hasPermi('resource:station:add')")
    @Log(title = "小站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResStation resStation)
    {
        return toAjax(resStationService.insertResStation(resStation));
    }

    /**
     * 修改小站
     */
    @PreAuthorize("@ss.hasPermi('resource:station:edit')")
    @Log(title = "小站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResStation resStation)
    {
        return toAjax(resStationService.updateResStation(resStation));
    }

    /**
     * 删除小站
     */
    @PreAuthorize("@ss.hasPermi('resource:station:remove')")
    @Log(title = "小站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resStationService.deleteResStationByIds(ids));
    }
}
